package com.penghaisoft.microwms.base.web.auth.service.impl;

import com.penghaisoft.microwms.base.web.auth.service.IMdTeamService;
import com.penghaisoft.microwms.base.web.team.dao.MdTeamMapper;
import com.penghaisoft.microwms.common.data.model.MdTeam;
import com.penghaisoft.microwms.common.dto.Resp;
import com.penghaisoft.microwms.common.page.Pager;
import com.penghaisoft.microwms.common.service.BaseService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 业务逻辑实现类
 * </p>
// *
 * @author
 * @createDate 
 **/
@Service("mdTeamService")
public class MdTeamServiceImpl extends BaseService implements IMdTeamService{
		@Resource
		private MdTeamMapper mdTeamMapper;
		
	  /**
	   * 新增记录
	   * @param mdTeam
	   * @return
	   */
		@Override
		public Resp create(MdTeam mdTeam){
			mdTeamMapper.create(mdTeam);
			return success();
		}

	  /**
	   * 删除记录（逻辑删除）
	   * @param mdTeam
	   * @return
	   */
		@Override
		public Resp delete(MdTeam mdTeam){
			mdTeamMapper.delete(mdTeam);
			return success();
		}
		
	  /**
	   * 查询列表
	   * @param
	   * @param condition
	   * @return
	   */
		@Override
		public Pager<MdTeam> findListByCondition(int page, int rows, MdTeam condition){
		    Pager<MdTeam> pager = new Pager<>();
		    pager.setPage(page);
		    pager.setRows(rows);
    		condition.preQuery();
    		long size = mdTeamMapper.queryCount(condition);
    		List<MdTeam> records = new ArrayList<>();
    		if(size > 0){
    			records = mdTeamMapper.queryList(pager,condition);
    		}
			pager.setRecords(records);
			pager.setTotalCount(size);
			return pager;
		}

	  /**
	   * 查询单条
	   * @param id
	   * @return
	   */
		@Override
		public MdTeam findById(String id){
			return mdTeamMapper.queryById(id);
		}
		
	  /**
	   * 修改记录
	   * @param mdTeam
	   * @return
	   */
		@Override
		public Resp update(MdTeam mdTeam){
			mdTeamMapper.updateBySelect(mdTeam);
			return success();
		}

	// 用班组名称或班组编码判断班组是否存在
	@Override
	public Boolean findIt(MdTeam mdTeam) {
		MdTeam obj = new MdTeam();
		obj.setTeamCode(mdTeam.getTeamCode());
		obj.setActiveFlag("1");
		long size1 = mdTeamMapper.queryCount(obj);
		obj.setTeamCode(null);
		obj.setTeamName(mdTeam.getTeamName());
		long size2 = mdTeamMapper.queryCount(obj);
		if (size1 == 0 && size2 == 0){
			return true;
		}
		return false;
	}

	/**
	 * wzhg 获取班组列表（下拉菜单使用）
	 * @return
     */
	@Override
	public List<MdTeam> getTeams(MdTeam mdTeam) {
		return mdTeamMapper.queryList(null,mdTeam);
	}

}
